/*     */ package nc.bs.to.m5x.maintain.rule.insert;
/*     */ 
/*     */ import java.util.HashMap;
/*     */ import java.util.HashSet;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ import nc.impl.pubapp.pattern.rule.IRule;
/*     */ import nc.itf.scmpub.reference.uap.org.StockOrgPubService;
/*     */ import nc.itf.scmpub.reference.uap.pf.PfServiceScmUtil;
/*     */ import nc.vo.ml.AbstractNCLangRes;
/*     */ import nc.vo.ml.NCLangRes4VoTransl;
/*     */ import nc.vo.org.StockOrgVO;
/*     */ import nc.vo.pub.lang.UFBoolean;
/*     */ import nc.vo.pub.lang.UFDouble;
/*     */ import nc.vo.pubapp.pattern.exception.ExceptionUtils;
/*     */ import nc.vo.pubapp.pattern.model.entity.bill.IBill;
/*     */ import nc.vo.pubapp.pattern.pub.MathTool;
/*     */ import nc.vo.pubapp.pattern.pub.PubAppTool;
/*     */ import nc.vo.pubapp.util.VORowNoUtils;
/*     */ import nc.vo.scmpub.res.billtype.TOBillType;
/*     */ import nc.vo.to.m5x.entity.BillHeaderVO;
/*     */ import nc.vo.to.m5x.entity.BillItemVO;
/*     */ import nc.vo.to.m5x.entity.BillVO;
/*     */ import nc.vo.to.m5x.enumeration.TransMode;
/*     */ import nc.vo.to.m5x.pub.M5XVOBusiRuleUtil;
/*     */ import nc.vo.trade.checkrule.VOChecker;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class FillDataRule
/*     */   implements IRule<BillVO>
/*     */ {
/*     */   public FillDataRule() {}
/*     */   
/*     */   public void process(BillVO[] vos)
/*     */   {
/*  46 */     for (BillVO bill : vos) {
/*  47 */       fillTransMode(bill);
/*  48 */       fillBusiType(bill);
/*  49 */       fillRowNo(bill);
/*  50 */       calculateHeadTotalNum(bill);
/*     */     }
/*  52 */     fillUnilateralflagRule(vos);
/*     */   }
/*     */   
/*     */   private void calculateHeadTotalNum(BillVO bill) {
/*  56 */     BillItemVO[] items = bill.getChildrenVO();
/*  57 */     UFDouble ntotalorigmny = UFDouble.ZERO_DBL;
/*  58 */     UFDouble ntotalastnum = UFDouble.ZERO_DBL;
/*  59 */     UFDouble ntotalpiece = UFDouble.ZERO_DBL;
/*  60 */     UFDouble ntotalvolume = UFDouble.ZERO_DBL;
/*  61 */     UFDouble ntotalweight = UFDouble.ZERO_DBL;
/*  62 */     for (BillItemVO item : items)
/*  63 */       if (item.getStatus() != 3)
/*     */       {
/*     */ 
/*     */ 
/*  67 */         if ((item.getBiolargessflag() == null) || (!item.getBiolargessflag().booleanValue()))
/*     */         {
/*  69 */           ntotalorigmny = MathTool.add(ntotalorigmny, item.getNorigtaxmny());
/*     */         }
/*  71 */         ntotalastnum = MathTool.add(ntotalastnum, item.getNastnum());
/*  72 */         ntotalpiece = MathTool.add(ntotalpiece, item.getNpiece());
/*  73 */         ntotalvolume = MathTool.add(ntotalvolume, item.getNvolume());
/*  74 */         ntotalweight = MathTool.add(ntotalweight, item.getNweight());
/*     */       }
/*  76 */     BillHeaderVO header = bill.getParentVO();
/*  77 */     header.setNtotalorigmny(ntotalorigmny);
/*  78 */     header.setNtotalastnum(ntotalastnum);
/*  79 */     header.setNtotalpiece(ntotalpiece);
/*  80 */     header.setNtotalvolume(ntotalvolume);
/*  81 */     header.setNtotalweight(ntotalweight);
/*     */     
/*  83 */     header.setStatus(1);
/*     */   }
/*     */   
/*     */   private void checkStordocFor5I(BillVO bill) {
/*  87 */     BillItemVO[] items = bill.getChildrenVO();
/*  88 */     for (BillItemVO item : items) {
/*  89 */       if (item.getStatus() != 3)
/*     */       {
/*     */ 
/*     */ 
/*  93 */         String coutStordoc = item.getCoutstordocid();
/*  94 */         if (VOChecker.isEmpty(coutStordoc)) {
///*  95 */           ExceptionUtils.wrappBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("4009011_0", "04009011-0112"));
/*     */         }
/*     */         
/*     */ 
/*     */ 
/*     */ 
/* 101 */         String cinStordoc = item.getCinstordocid();
/* 102 */         if (VOChecker.isEmpty(cinStordoc)) {
/* 103 */           ExceptionUtils.wrappBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("4009011_0", "04009011-0113"));
/*     */         }
/*     */         
/*     */ 
/*     */ 
/*     */ 
/* 109 */         if (null != coutStordoc && coutStordoc.equals(cinStordoc)) {
/* 110 */           ExceptionUtils.wrappBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("4009011_0", "04009011-0114"));
/*     */         }
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   private void fillBusiType(BillVO bill)
/*     */   {
/* 120 */     if (PubAppTool.isNull(bill.getParentVO().getCbiztypeid()))
/*     */     {
/* 122 */       PfServiceScmUtil.setBusiType(new IBill[] { bill }, TOBillType.TransOrder.getCode());
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   private void fillRowNo(BillVO bill)
/*     */   {
/* 130 */     VORowNoUtils.setVOsRowNoByRule(bill.getChildrenVO(), "crowno");
/*     */   }
/*     */   
/*     */   private void fillTransMode(BillVO bill) {
/* 134 */     Integer ftransmode = bill.getParentVO().getFmodeflag();
/*     */     
/* 136 */     ftransmode = M5XVOBusiRuleUtil.getTransMode(bill);
/*     */     
/* 138 */     if (null == ftransmode) {
/* 139 */       String message = NCLangRes4VoTransl.getNCLangRes().getStrByID("4009011_0", "04009011-0115");
/*     */       
/*     */ 
/* 142 */       ExceptionUtils.wrappBusinessException(message);
/*     */     }
/* 144 */     bill.getParentVO().setFmodeflag(ftransmode);
/*     */     
/* 146 */     if (TransMode.TRANSMODE_5I.equalsValue(ftransmode)) {
/* 147 */       checkStordocFor5I(bill);
/*     */     }
/*     */   }
/*     */   
/*     */   private void fillUnilateralflagRule(BillVO[] bills) {
/* 152 */     Set<String> inStockOrgs = new HashSet();
/* 153 */     for (BillVO bill : bills) {
/* 154 */       if (bill.getParentVO().getBunilateralflag() == null) {
/* 155 */         inStockOrgs.add(bill.getParentVO().getCinstockorgid());
/*     */       }
/*     */     }
/* 158 */     if (!inStockOrgs.isEmpty()) {
/* 159 */       StockOrgVO[] stockOrgs = StockOrgPubService.queryStockOrgByIDs((String[])inStockOrgs.toArray(new String[0]), new String[] { "pk_stockorg", "enablestate" });
/*     */       
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 165 */       Map<String, Integer> stockMap = new HashMap();
/* 166 */       if ((stockOrgs != null) && (stockOrgs.length > 0)) {
/* 167 */         for (StockOrgVO stockOrgvo : stockOrgs) {
/* 168 */           stockMap.put(stockOrgvo.getPk_stockorg(), stockOrgvo.getEnablestate());
/*     */         }
/*     */       }
/*     */       
/*     */ 
/*     */ 
/* 174 */       if (!stockMap.isEmpty()) {
/* 175 */         for (BillVO bill : bills) {
/* 176 */           Integer enableState = (Integer)stockMap.get(bill.getParentVO().getCinstockorgid());
/*     */           
/*     */ 
/* 179 */           if (2 != enableState.intValue()) {
/* 180 */             bill.getParentVO().setBunilateralflag(UFBoolean.TRUE);
/* 181 */             bill.getParentVO().setCsettlepathid(null);
/*     */           }
/*     */           else {
/* 184 */             bill.getParentVO().setBunilateralflag(UFBoolean.FALSE);
/*     */           }
/*     */         }
/*     */       }
/*     */     }
/*     */   }
/*     */ }

/* Location:           E:\lifan\code\home\modules\to\META-INF\lib\to_transferringorder.jar
 * Qualified Name:     nc.bs.to.m5x.maintain.rule.insert.FillDataRule
 * Java Class Version: 7 (51.0)
 * JD-Core Version:    0.7.0.1
 */